import React from 'react';
import { GameHeaderProps } from '../../types';
import {
  SparklesIcon, ArrowUturnLeftIcon, ArrowDownTrayIcon, DocumentTextIcon,
  ClipboardDocumentListIcon, ClipboardIcon, HomeIcon, EyeIcon, CogIcon, CodeBracketSquareIcon, CpuChipIcon
} from '../icons';

const GameHeader: React.FC<GameHeaderProps> = ({
  gameData,
  isLoading,
  currentTurn,
  onShowRulebook,
  onShowAiConfig,
  onShowAiContext,
  onCopyImageQuery,
  onConsolidateKeyInfo,
  onBacktrack,
  onSaveGame,
  onExportGame,
  onExportTxt,
  onGoToMainMenu,
  showFunctionCallDebugButton,
  onShowFunctionCallDebug,
  onGoToSettings,
  isHybridMode,
  isCalculationHelperEnabled,
  onToggleCalculationHelper,
}) => {
  return (
    <header className="mb-2 sm:mb-4 flex flex-wrap justify-between items-center gap-2 p-2 bg-gray-800 rounded-lg shadow-md">
      <h2 className="text-xl sm:text-2xl font-bold text-transparent bg-clip-text bg-gradient-to-r from-sky-400 to-cyan-300 truncate flex-shrink max-w-[calc(100%-320px)] sm:max-w-[calc(100%-380px)]" title={gameData.rulebook.gameName}>{gameData.rulebook.gameName}</h2>
      <div className="flex items-center space-x-1 sm:space-x-2 flex-wrap">
        <button title="编辑游戏规则/故事" onClick={onShowRulebook} data-guide-id="rulebook-btn" className="p-2 bg-orange-600 hover:bg-orange-700 rounded-full text-white"><DocumentTextIcon className="w-5 h-5" /></button>
        <button title="编辑AI配置" onClick={onShowAiConfig} data-guide-id="ai-config-btn" className="p-2 bg-purple-600 hover:bg-purple-700 rounded-full text-white"><CodeBracketSquareIcon className="w-5 h-5" /></button>
        <button title="通用设置" onClick={onGoToSettings} data-guide-id="gamescreen-settings-btn" className="p-2 bg-gray-500 hover:bg-gray-600 rounded-full text-white"><CogIcon className="w-5 h-5" /></button>
        <button title="查看AI上下文" onClick={onShowAiContext} data-guide-id="ai-context-btn" className="p-2 bg-teal-500 hover:bg-teal-600 rounded-full text-white"><EyeIcon className="w-5 h-5" /></button>
        {isHybridMode && (
            <button
                title={`计算助手AI: ${isCalculationHelperEnabled ? '已启用' : '已禁用'}`}
                onClick={onToggleCalculationHelper}
                className={`p-2 rounded-full text-white transition-colors ${isCalculationHelperEnabled ? 'bg-lime-600 hover:bg-lime-700' : 'bg-gray-600 hover:bg-gray-500'}`}
            >
                <CpuChipIcon className="w-5 h-5" />
            </button>
        )}
        {showFunctionCallDebugButton && (
           <button title="查看函数调用日志" onClick={onShowFunctionCallDebug} className="p-2 bg-lime-600 hover:bg-lime-700 rounded-full text-white"><CodeBracketSquareIcon className="w-5 h-5" /></button>
        )}
        {currentTurn?.imageQuery && (
          <button title="复制图片提示词" onClick={onCopyImageQuery} className="p-2 bg-sky-500 hover:bg-sky-600 rounded-full text-white">
            <ClipboardIcon className="w-5 h-5" />
          </button>
        )}
        <button title="整合关键信息" onClick={onConsolidateKeyInfo} data-guide-id="consolidate-btn" disabled={isLoading || gameData.gameHistory.length < 1} className="p-2 bg-pink-600 hover:bg-pink-700 rounded-full text-white disabled:opacity-50"><SparklesIcon className="w-5 h-5" /></button>
        <button title="回溯" onClick={onBacktrack} data-guide-id="backtrack-btn" disabled={isLoading || gameData.gameHistory.length <= 1} className="p-2 bg-yellow-500 hover:bg-yellow-600 rounded-full text-white disabled:opacity-50"><ArrowUturnLeftIcon className="w-5 h-5" /></button>
        <button title="保存" onClick={onSaveGame} data-guide-id="save-game-btn" disabled={isLoading} className="p-2 bg-green-500 hover:bg-green-600 rounded-full text-white disabled:opacity-50"><ArrowDownTrayIcon className="w-5 h-5" /></button>
        <button title="导出存档 (JSON)" onClick={onExportGame} data-guide-id="export-game-btn" disabled={isLoading} className="p-2 bg-indigo-500 hover:bg-indigo-600 rounded-full text-white disabled:opacity-50"><ArrowDownTrayIcon className="w-5 h-5" /></button>
        <button title="导出为文本 (.txt)" onClick={onExportTxt} className="p-2 bg-cyan-600 hover:bg-cyan-700 rounded-full text-white disabled:opacity-50"><ClipboardDocumentListIcon className="w-5 h-5" /></button>
        <button title="主菜单" onClick={onGoToMainMenu} data-guide-id="main-menu-btn" className="p-2 bg-gray-600 hover:bg-gray-700 rounded-full text-white"><HomeIcon className="w-5 h-5" /></button>
      </div>
    </header>
  );
};

export default GameHeader;
